name: Release

on: 
  workflow_dispatch:
    inputs:
      package:
        description: 'Package to be deployed'
        required: true
        default: 'paddlenlp'
        type: choice
        options:
        - paddlenlp
        - paddle-pipelines
        - ppdiffusers

jobs:
  Release:
    name: Release
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v1
        with:
          python-version: 3.8
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install setuptools wheel twine
      - name: Should Deploy
        id: should-deploy
        env: 
          PACKAGE: ${{ inputs.package }}
        run: python scripts/should_deploy.py  --name $PACKAGE >> $GITHUB_OUTPUT

      - name: Check Branch
        id: check-branch
        run: |
          if [[ ${{ github.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
              echo "match=true" >> $GITHUB_OUTPUT
          fi  # See: https://stackoverflow.com/a/58869470/1123955

      - name: Is A Publish Branch
        if: steps.check-branch.outputs.match == 'true' && steps.should-deploy.outputs.should_deploy == 'true'
        env:
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: ${{ secrets.paddlenlp }}
          PACKAGE: ${{ inputs.package }}
          PADDLENLP_STABLE_VERSION: "true"
        run: |
          make deploy-$PACKAGE

      - name: Should Not Deploy To Pypi Server
        if: steps.should-deploy.outputs.should_deploy != 'true'
        run: echo 'should not deploy pypi server'

      - name: Is Not A Publish Branch
        if: steps.check-branch.outputs.match != 'true'
        run: echo 'Not A Publish Branch'
